﻿Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports Forecast.Logica.Enumeradores
Imports Forecast.Logica.Servicios
Public Class IniciarSesion
    Inherits System.Web.UI.Page
    Private Shared _servUsuarios As ServUsuarios

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        _servUsuarios = New ServUsuarios()
        If Not Page.IsPostBack Then
            ' mpeLogin.Show()
            ErroresLogin.Visible = False
        End If
    End Sub

    Protected Sub LbContraseñaOlvidadaClick(sender As Object, e As EventArgs) Handles lbConstrasenaOlbvidada.Click

    End Sub

    Protected Sub BtnIniciarSesionClick(sender As Object, e As EventArgs) Handles btnSi.Click
        Dim SiError As Boolean
        SiError = ValidarCampos()

        If SiError = True Then
            Exit Sub
        End If

        Dim usuario = _servUsuarios.ObtenerUsuarioPorUserPassword(txtNombreUsuario.Text, txtContrasena.Text)
        If usuario.IdUsuario = 0 Then
            lblErroresLogin.Text = "<b>Error: </b>Nombre usuario o contraseña incorrecta"
            ErroresLogin.Visible = True
        Else
            ErroresLogin.Visible = False
            Session("usuario") = usuario
            Session("ActualizarListado") = True
            Session("MostrarListado") = True
            Response.Redirect("Formularios/listado.aspx")
            'Response.Redirect("Formularios/forecast.aspx")
        End If
    End Sub
    Private Function ValidarCampos() As Boolean
        ' LimpiarErrores
        txtNombreUsuario.CssClass = "w70p"
        txtContrasena.CssClass = "w70p"
        Dim SiError As Boolean
        SiError = False

        If txtNombreUsuario.Text.Trim() = "" Then
            txtNombreUsuario.CssClass = "error"
            SiError = True
        End If
        If txtContrasena.Text.Trim() = "" Then
            txtContrasena.CssClass = "error"
            SiError = True
        End If

        Return SiError

    End Function
    Protected Sub BtnEnviarClick(sender As Object, e As EventArgs) Handles btnEnviar.Click

    End Sub

    Protected Sub BtnVolverClick(sender As Object, e As EventArgs) Handles btnVolver.Click

    End Sub
End Class